Grokking Microservices Design Patterns
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction
Who Should Take This Course?
The Course at a Glance
Strangler Fig Pattern
Introduction
The Problem: Legacy Systems
The Strangler Pattern: A Solution
The Architecture of the Strangler Pattern
Strangler Pattern: A Detailed Example
Key Insights and Implications
API Gateway Pattern
Introduction to the API Gateway Pattern
Advantages of API Gateway Pattern
API Gateway Pattern: An Example
Performance Implications
System Design Example
Backends for Frontends (BFF) Pattern
Introduction to BFF
The Problem: Traditional Backend Models
The Architecture of the BFF Pattern
BFF Pattern: An Example
Performance Implications
System Design Examples
Service Discovery Pattern
What is Service Discovery Pattern?
The Problem: Service Coordination in Distributed Systems
Service Discovery Pattern: A Solution
The Architecture of the Service Discovery Pattern
The Inner Workings of the Service Discovery Pattern
Service Discovery Pattern: An Example
Performance Implications and Special Considerations
System Design Examples
Security Considerations
Introduction
The Problem: The Struggles of Distributed Systems and Service Failures
The Circuit Breaker Pattern: An Effective Shield Against Cascading Failures
Circuit Breaker Pattern: An Example
Performance Implications and Special Considerations
System Design Examples
Summary
Introduction
The Problem: Failure Propagation in Distributed Systems
The Bulkhead Pattern: A Solution
The Architecture
The Inner Workings
Bulkhead Pattern: A Example
Performance Implications and Special Considerations
System Design Examples
Conclusion
Introduction
The Retry Pattern: A Solution to Unreliable External Resources
The Architecture of the Retry Pattern
Retry Pattern: An Example
Performance Implications
Use Cases and System Design Examples
Conclusion
Introduction to the Sidecar Pattern
The Problem: Monolithic Application Management
A Solution to the Monolithic Mayhem
The Architecture of the Sidecar Pattern
Sidecar Pattern: Bringing Theory to Practice with an Example
Performance Implications
System Design Examples: Bringing the Sidecar Pattern to Life
Introduction to Saga Pattern
The Problem: Traditional Transaction Models
The Saga Pattern: A Solution
The Architecture of the Saga Pattern
The Inner Workings of the Saga Pattern
Saga Pattern: A Example
Performance Implications
System Design Examples
Conclusion
Introduction
The Problem: Managing Complex Interactions in Distributed Systems
Event-Driven Architecture: A Promising Solution
The Architecture of the Event-Driven Architecture Pattern
The Inner Workings of the Event-Driven Architecture Pattern
Event-Driven Architecture Pattern: An Example
Performance Implications and Special Considerations
Use Cases and System Design Examples
Conclusion
Introduction
The Problem: Traditional CRUD Operations
CQRS Pattern: A Solution
The Architecture of the CQRS Pattern
The Inner Workings of the CQRS Pattern
CQRS Pattern: An Example
Issues, Special Considerations, and Performance Implications
System Design Examples
Introduction
The Problem: Configuration Management in a Microservices Architecture
The Solution: Configuration Externalization Pattern
Unveiling the Architecture: How Does Configuration Externalization Work?
Delving into Code: An Example
Considerations and Implications
Use Cases and Real-world Examples
Conclusion
Embrace the Future of Software Architecture
System Design Examples

After a deep dive into the details of the Service Discovery pattern, it's time to zoom out and consider the bigger picture. How does this pattern apply in real-world scenarios? What are some examples of systems that use Service Discovery to coordinate their services? Let's take a look.

Use Cases

Let's first discuss where and when you might want to use the Service Discovery pattern. In general, this pattern is best suited to large, distributed systems where services need to communicate with each other but the locations of those services are subject to change.

Microservices Architectures

One prime example is a system designed around microservices. In a microservices architecture, the system is divided into small, independent services that each perform a specific function. These services need to communicate with each other to achieve the system's overall functionality.

Without Service Discovery, managing the connections between these services can become a nightmare, particularly as the system scales. With Service Discovery, services can dynamically discover and communicate with each other, significantly reducing the complexity of managing these inter-service connections.

Cloud-based Systems

Another common use case is in cloud-based systems. In the cloud, services can be dynamically allocated to different servers or locations based on demand, cost, and other factors. This can make it difficult for services to find each other without some form of Service Discovery.

With Service Discovery, services can register their new location with the Service Registry whenever they move. This makes it easy for other services to find them, regardless of where they are currently located.

System Design Examples

To illustrate these concepts, let's take a look at a couple of system design examples that make use of the Service Discovery pattern.

Example 1: E-commerce System

Consider an e-commerce system composed of multiple services: a User Service for handling user data, an Inventory Service for managing product inventory, a Shopping Cart Service for managing user shopping carts, and an Order Service for processing orders.

Without Service Discovery, each of these services would need to know the locations of the other services they interact with. If the Inventory Service moves to a new server, the User Service and Shopping Cart Service would need to update their connections accordingly.

With Service Discovery, however, the Inventory Service simply registers its new location with the Service Registry. The User Service and Shopping Cart Service can then query the Service Registry to find the Inventory Service's new location. This makes the system much more flexible and resilient to change.

Example 2: Streaming Platform

Another example could be a streaming platform where there are multiple services for managing user profiles, handling video streaming, processing payments, and recommending content based on user behavior.

In this scenario, the streaming service might need to be highly scalable to handle peak viewing times. This could involve dynamically adding or removing instances of the streaming service based on demand. Without Service Discovery, this could lead to broken connections as services try to communicate with instances that no longer exist.

With Service Discovery, the streaming service instances can register and deregister with the Service Registry as they are added and removed. Other services can then always find a valid instance of the streaming service by querying the Service Registry.

Real-World Usage

Service discovery is used in almost every large-scale microservice system in one form or another. Here are a few real-world examples and case studies:

  • Netflix: Netflix is often cited as a pioneer in microservices. Netflix's service discovery system is Eureka. In Netflix’s architecture, hundreds of services register with Eureka, and Netflix’s various applications query Eureka to find service instances. This allows Netflix to scale services up/down and move them across data centers without clients needing to know the details. Eureka has proven to handle the scale of Netflix streaming services.

  • Kubernetes: Arguably the most widespread use of service discovery today comes built into Kubernetes. Kubernetes has a concept of a Service (a stable virtual IP and DNS name for a set of pods). When new pods come up or old ones die, Kubernetes updates its internal endpoints list, and through kube-proxy or other mechanisms, ensures that traffic to the Service is load-balanced to current pods. For discovery, Kubernetes automatically configures DNS entries so that if Service X exists in the cluster, any pod can simply lookup http://service-x (or a full DNS name) and get to it. Under the hood, Kubernetes maintains an etcd-based registry of pods and services and a cluster DNS service (CoreDNS) that answers queries based on the current registry data. So, any app running in Kubernetes is effectively using a server-side discovery pattern via DNS and the cluster’s network proxies.

  • Airbnb (SmartStack): Before Kubernetes became popular, Airbnb developed a system called SmartStack for service discovery in their microservices architecture. SmartStack used HAProxy (a software load balancer) on every host and a distributed coordination service (ZooKeeper) as the registry. Each service on a host would register via a local agent, and the local HAProxy would update its configuration to route to services. This effectively gave every application a local load balancer for other services. They discovered that manually keeping track of service pools was untenable and built SmartStack to automate it.

  • Consul in Production: HashiCorp Consul is used by many companies for service discovery (and configuration). It provides DNS-based discovery as well as an HTTP API. Companies like Stripe and PagerDuty have used Consul to coordinate service discovery in their infrastructures. Consul’s ability to work across multiple data centers and provide DNS-based discovery makes it a popular choice in enterprise environments where Kubernetes might not be the orchestrator, or where a more platform-agnostic solution is needed.

  • Service Mesh Examples: Large tech companies like Google and Lyft have gravitated toward service meshes. Lyft’s Envoy was initially built to solve service discovery, routing, and observability at Lyft. Instead of each app doing discovery, Envoy sidecars receive updates from a central control plane about where every service is. So, when Service A calls Service B, it actually calls Envoy locally, and Envoy knows all the instances of B and can route intelligently. This decouples discovery logic completely from the application code and puts it into infrastructure.

In summary, the Service Discovery pattern is a powerful tool for managing service coordination in distributed systems. It allows services to dynamically discover and communicate with each other, reducing the complexity of managing connections and making the system more flexible and scalable. However, like any tool, it's important to understand its trade-offs and use it wisely.

Performance Implications and Special Considerations
Security Considerations
Mark as Completed

On this page

Use Cases

Microservices Architectures

Cloud-based Systems

System Design Examples

Example 1: E-commerce System

Example 2: Streaming Platform